<template>
  <div>
    <header>
      <div class="container-login">
        <div class="logo">智慧英语</div>
        <nav>
          <ul>
            <li><a>nav1</a></li>
            <li><a>nav2</a></li>
            <li><a>nav3</a></li>
            <li><a>nav4</a></li>
          </ul>
        </nav>
      </div>
    </header>
    <section class="main">
      <div class="login-bg">
        <div class="login-box">
          <div class="login-form-bg">
            <div class="login-form">
              <el-form
                      :model="loginForm"
                      ref="loginForm"
                      :rules="loginRules">
                <el-form-item prop="managerName">
                  <el-input
                          type="text"
                          placeholder="账号"
                          icon="user"
                          v-model.number="loginForm.managerName"></el-input>
                </el-form-item>
                <el-form-item prop="managerPassword">
                  <el-input
                          type="password"
                          placeholder="密码"
                          icon="password"
                          v-model.number="loginForm.managerPassword"></el-input>
                </el-form-item>
              </el-form>
              <el-button
                      style="width: 100%;"
                      type="primary"
                      :loading="isLoading"
                      @click="submitForm('loginForm')"
                      size="large">{{btnTex}}</el-button>
              <p style="text-align: center;margin-top: 10px;">忘记密码?</p>
            </div>
          </div>
        </div>
      </div>
    </section>
    <div class="container">
      <div class="contact">
        <div class="contact-icon">
          <img src="../images/login-page/login-phoneIcon.png" />
          <ul>
            <li><a>详情咨询</a></li>
            <li><a>028-88888888</a></li>
          </ul>
        </div>
        <nav class="contact-info">
          <ul>
            <li><a>专业</a></li>
            <li><a>定制</a></li>
            <li><a>便捷</a></li>
          </ul>
        </nav>
      </div>
    </div>
    <footer>
      <p><a>关于我们</a><a>法律声明</a><a>友情链接</a></p>
      <p><a>Copyright©2014-2016  All Rights Reserved</a></p>
    </footer>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    name: 'loginPage',
    data:function(){
      var checkName = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('账号不能为空'));
        }
        callback();
      };
      var checkPassword = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('密码不能为空'));
        }
        callback();
      };
      return {
        isLoading:false,
        btnTex : "登录",
        fullscreenLoading: false,
        loginForm: {
            managerName: '',
            managerPassword:''
        },
        loginRules: {
            managerName: [
            //{ required: true, message:'账号不能为空', trigger: 'blur' },
            { validator: checkName, trigger: 'blur' },
          ],
            managerPassword: [
            //{ required:true, message:'密码不能为空', trigger: 'blur' }
            {  validator: checkPassword, trigger: 'blur' }
          ]
        }
      }
    },
    methods : {
      gotoWebApp : function(){
        var _this = this;
        _this.btnTex = "登录中,请稍后...";
        _this.isLoading = true;
        this.$rsClient.post("/adminafter/login?managerName="+this.loginForm.managerName+"&managerPassword="+this.loginForm.managerPassword,this.loginForm,(result) => {
          if(result && result.status == "SUCCESS"){
            this.$store.commit("LOGIN_SUCCESS",result);
            this.$rsClient.setHeader(result.token);
            this.$util.createCookie("loginUser",JSON.stringify(result),1);
            _this.isLoading = false;
            _this.btnTex = "已登录";
            _this.$router.push("/produce/main");
          }else{

            _this.isLoading = false;
            _this.btnTex = "登录";
            if(result.status == "NOT_FOUND"){
              this.$message.error("账号不存在");
            }else if(result.status == "WRONG_PASS"){
              this.$message.error("密码错误");
            }else if(result.status == "LOCKED"){
              this.$message.error("账号锁定,请联系管理员");
            }

          }

        },(error) => {
          _this.isLoading = false;
          _this.btnTex = "登录";
          this.$message.error(error.errorMessage);
        });
      },
      submitForm:function(formName) {
        var _this = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.info("表单验证状态:"+valid)
            _this.gotoWebApp();
          } else {
            console.info("表单验证状态:"+valid)
            return false;
          }
        });
      }
    },
    components : {

    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less">
  @import "../less/unite.less";
  .login-page header{
    min-width: 102.4rem;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    height: 50px;
  }
  div.container-login{
    width: 90%;
    margin: 0 auto;
    overflow: hidden;
  }
  .logo{
    float: left;
    height: 60px;
    font-size: 28px;
    color: @color-main;
    line-height: 60px;
  }
  header{
    display: none;
    background: @color-white;
  }
  header nav{
    float: right;
  }
  header nav ul{
    overflow: hidden;
    height: 60px;
  }
  header nav li{
    float: left;
    margin-top: 20px;
    vertical-align: middle;
    padding: 0 8px;
    border-right: solid 1px @colorSearch-btn;
  .elementAnimate();
  }
  header nav li:last-child{
    border: none;
  }
  header nav li:hover{
    color: @color-main;
    cursor: pointer;
  .elementAnimate();
  }
  header nav li>a{
    color: #717171;
    font-size: 16px;
  }
  /*footer*/
  .main{
    height: 456px;
  .elementAnimate();
  }
  @media screen and (min-width: 1400px) {
    .main{
      height: 486px;
    .elementAnimate();
    }
  }
  @media screen and (min-width: 1580px) {
    .main{
      height: 546px;
    .elementAnimate();
    }
  }
  @media screen and (min-width: 1580px) {
    .main{
      height: 586px;
    .elementAnimate();
    }
  }
  .login-bg{
    height: @fullHeight;
    background-image: url("../images/login-page/login-bg.jpg");
  .backgroundSize(center,center,cover);
  }
  .login-box{
    position: relative;
    width: 1020px;
    padding: 0 15px;
    height: 100%;
    margin: 0 auto;
  }
  .login-form-bg{
    position: absolute;
    z-index: 1;
    right: 30px;
    bottom: -40px;
    width: 507px;
    height: 270px;
    background-image: url("../images/login-page/login-form-bg.png");
  .backgroundSize(center,bottom,contain);
  }
  .login-form{
    width: 350px;
    padding: 20px;
    height: @fullHeight;
    background-color: @color-white;
    margin: 0 auto;
  .boxShadow(0,0,5px,2px,rgba(0,0,0,0.15));
  .borderRadus(4px);
  }
  .login-form form{
    margin-top: 30px;
  }
  .login-form .el-input__icon+.el-input__inner{
    padding-left: 35px!important;
  }
  .login-form .el-input__icon{
    left: 0;
  }
  .login-form form .el-icon-loading{
    display: none!important;
  }
  .login-submitBtn{
    margin-top: 20px;
  }
  .login-submitBtn button{
    border: none;
    outline: none;
    width: @fullWidth;
    padding: 12px 6px;
    background: @color-main;
    color: @color-white;
    font-size: 20px;
    text-align: center;
  .borderRadus(4px);
  .elementAnimate();
  }
  .login-submitBtn button:hover{
    background: @color-main+#111111;
  .elementAnimate();
  }
  .login-form a{
    padding: 1.0rem;
    display: block;
    color: #717171;
    text-align: center;
  .elementAnimate();
  }
  .login-form a:hover{
    color: inherit;
  .elementAnimate();
  }
  /*联系方式*/
  .contact{
    margin-top: 80px;
    margin-bottom: 50px;
    padding: 0 120px;
    overflow: hidden;
  }
  .contact-icon{
    float: left;
    margin-top: 8px;
  }
  .contact-icon img{
    float: left;
    width: 36px;
  }
  .contact-icon ul{
    float: right;
    margin-left: 20px;
    margin-top: 6px;
  }
  .contact-icon ul>li>a{
    color: #717171;
  }
  .contact-info{
    float: right;
  }
  .contact-info ul{
    overflow: hidden;
    height: 50px;
  }
  .contact-info li{
    float: left;
    margin-top: 17px;
    vertical-align: middle;
    padding: 0 12px;
    border-right: solid 1px @colorSearch-btn;
    font-size: 20px;
  }
  .contact-info li>a{
    color: #717171;
  }
  .contact-info li:last-child{
    border: none;
  }

  /*footer*/
  footer{
    background: #ebebeb;
    padding: 25px;
  }
  footer p{
    margin-bottom: 15px;
    text-align: center;
  }
  footer p a{
    margin: 0 8px;
    cursor: pointer;
    color: #000000;
  }
</style>


